using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.reports;
namespace TVSGPP.reports
{
	public class frmPrescriptions : Form
	{
		private IContainer components = null;
		private Label label4;
		private DateTimePicker txttoDay;
		private Label label3;
		private DateTimePicker txtfromDay;
		private GroupBox groupBox1;
		private Button btnOK;
		private Button btnCancel;
		private Func objFunc = new Func();
		public DataTable objTable = new DataTable();
		private double reportTotalMoney = 0.0;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.label4 = new Label();
			this.txttoDay = new DateTimePicker();
			this.label3 = new Label();
			this.txtfromDay = new DateTimePicker();
			this.groupBox1 = new GroupBox();
			this.btnOK = new Button();
			this.btnCancel = new Button();
			base.SuspendLayout();
			this.label4.AutoSize = true;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label4.Location = new Point(90, 59);
			this.label4.Name = "label4";
			this.label4.Size = new Size(66, 15);
			this.label4.TabIndex = 59;
			this.label4.Text = "Đến ngày :";
			this.txttoDay.CustomFormat = "dd/MM/yyyy HH:mm:ss";
			this.txttoDay.Font = new Font("Arial", 9f);
			this.txttoDay.Format = DateTimePickerFormat.Custom;
			this.txttoDay.Location = new Point(159, 56);
			this.txttoDay.Name = "txttoDay";
			this.txttoDay.Size = new Size(150, 21);
			this.txttoDay.TabIndex = 58;
			this.label3.AutoSize = true;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label3.Location = new Point(97, 32);
			this.label3.Name = "label3";
			this.label3.Size = new Size(59, 15);
			this.label3.TabIndex = 57;
			this.label3.Text = "Từ ngày :";
			this.txtfromDay.CustomFormat = "dd/MM/yyyy HH:mm:ss";
			this.txtfromDay.Font = new Font("Arial", 9f);
			this.txtfromDay.Format = DateTimePickerFormat.Custom;
			this.txtfromDay.Location = new Point(159, 29);
			this.txtfromDay.Name = "txtfromDay";
			this.txtfromDay.Size = new Size(150, 21);
			this.txtfromDay.TabIndex = 56;
			this.groupBox1.Location = new Point(7, 4);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(321, 90);
			this.groupBox1.TabIndex = 60;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thời gian báo cáo";
			this.btnOK.Cursor = Cursors.Hand;
			this.btnOK.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnOK.Location = new Point(125, 100);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new Size(100, 30);
			this.btnOK.TabIndex = 61;
			this.btnOK.Text = "Báo cáo";
			this.btnOK.UseVisualStyleBackColor = true;
			this.btnOK.Click += new EventHandler(this.btnOK_Click);
			this.btnCancel.Cursor = Cursors.Hand;
			this.btnCancel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnCancel.Location = new Point(226, 100);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new Size(100, 30);
			this.btnCancel.TabIndex = 62;
			this.btnCancel.Text = "Thoát [ ESC ]";
			this.btnCancel.UseVisualStyleBackColor = true;
			this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(334, 136);
			base.Controls.Add(this.btnCancel);
			base.Controls.Add(this.btnOK);
			base.Controls.Add(this.label4);
			base.Controls.Add(this.txttoDay);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.txtfromDay);
			base.Controls.Add(this.groupBox1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(350, 170);
			this.MinimumSize = new Size(350, 170);
			base.Name = "frmPrescriptions";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: BẢNG KÊ ĐƠN THUỐC";
			base.KeyDown += new KeyEventHandler(this.frmPrescriptions_KeyDown);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmPrescriptions()
		{
			this.InitializeComponent();
			Program.strConnectionString = this.objFunc.strConnectionString;
		}
		private void frmPrescriptions_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyData == Keys.Escape)
			{
				this.objTable = null;
				base.Close();
			}
		}
		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.objTable = null;
			base.Close();
		}
		private void btnOK_Click(object sender, EventArgs e)
		{
			this.getBill();
			base.Close();
		}
		public void getBill()
		{
			try
			{
				this.reportTotalMoney = 0.0;
				DataColumn column = new DataColumn("Order", typeof(string));
				DataColumn column2 = new DataColumn("Patients", typeof(string));
				DataColumn column3 = new DataColumn("Product", typeof(string));
				DataColumn column4 = new DataColumn("Unit", typeof(string));
				DataColumn column5 = new DataColumn("Price", typeof(string));
				DataColumn column6 = new DataColumn("Number", typeof(string));
				DataColumn column7 = new DataColumn("Money", typeof(string));
				DataColumn column8 = new DataColumn("Doctor", typeof(string));
				this.objTable.Columns.Add(column);
				this.objTable.Columns.Add(column2);
				this.objTable.Columns.Add(column3);
				this.objTable.Columns.Add(column4);
				this.objTable.Columns.Add(column5);
				this.objTable.Columns.Add(column6);
				this.objTable.Columns.Add(column7);
				this.objTable.Columns.Add(column8);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlParameter sqlParameter = new SqlParameter("objDate1", SqlDbType.DateTime);
				SqlParameter sqlParameter2 = new SqlParameter("objDate2", SqlDbType.DateTime);
				sqlParameter.Value = this.txtfromDay.Value;
				sqlParameter2.Value = this.txttoDay.Value;
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.Parameters.Add(sqlParameter2);
				frmPrescriptionsPrint.timeReport = "Từ " + this.txtfromDay.Value.ToString() + " Đến " + this.txttoDay.Value.ToString();
				sqlCommand.CommandText = "SELECT * FROM [TabBill] WHERE [TypeInput] = 'OUT4' AND [TabBill].[CreateDate] BETWEEN @objDate1 AND @objDate2 ORDER BY [TabBill].[CreateDate] ASC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					this.objTable.Rows.Add(new object[]
					{
						sqlDataReader["ID"].ToString(),
						"   [-:-] " + sqlDataReader["_Name"].ToString() + sqlDataReader["_Age"].ToString(),
						"[-:-]   " + sqlDataReader["_Name"].ToString() + " - Tuổi : " + sqlDataReader["_Age"].ToString(),
						"",
						"",
						"",
						"",
						sqlDataReader["_DoctorName"].ToString()
					});
					this.getProduct(this.objTable, sqlDataReader["ID"].ToString());
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				frmPrescriptionsPrint.totalMoney = string.Format(Program.lenAffterDecimal, this.reportTotalMoney);
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public void getProduct(DataTable objTable, string billID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlParameter sqlParameter = new SqlParameter("objDate1", SqlDbType.DateTime);
				SqlParameter sqlParameter2 = new SqlParameter("objDate2", SqlDbType.DateTime);
				sqlParameter.Value = this.txtfromDay.Value;
				sqlParameter2.Value = this.txttoDay.Value;
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.Parameters.Add(sqlParameter2);
				sqlCommand.CommandText = "SELECT * FROM [TabDetailBill] WHERE [billID] = '" + billID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				int num = 0;
				double num2 = 0.0;
				while (sqlDataReader.Read())
				{
					num++;
					objTable.Rows.Add(new object[]
					{
						num.ToString(),
						"",
						sqlDataReader["productName"].ToString(),
						sqlDataReader["productUnit"].ToString(),
						sqlDataReader["productPrice2"].ToString(),
						sqlDataReader["productNumber"].ToString(),
						sqlDataReader["ProductMoney"].ToString(),
						""
					});
					num2 += double.Parse(sqlDataReader["ProductMoney"].ToString());
				}
				objTable.Rows.Add(new object[]
				{
					"",
					"",
					"",
					"",
					"",
					"Tổng tiền : ",
					string.Format(Program.lenAffterDecimal, num2),
					""
				});
				this.reportTotalMoney += num2;
				sqlDataReader.Close();
				sqlConnection.Close();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}
}
